package org.rednebula.framework.core.context;

import java.io.Serializable;

import org.rednebula.framework.core.BasicContext;
import org.springframework.context.ApplicationContext;




public class SpringContext extends BasicContext implements Serializable {
	ApplicationContext context;

	public SpringContext(ApplicationContext context) {
		super();
		this.setName(SPRING);
		this.context=context;
	}

	public <T> T get(String key) {
		if(this.isSelf(key))return (T)this.getContext();
		return (T)getContext().getBean(key);
	}

	public <T> T get(Class<T> type) {
		return (T)getContext().getBean(type.getName());
	}

	public boolean has(String name) {
		return this.isSelf(name)|| getContext().containsBean(name);
	}

	public ApplicationContext getContext() {
		return context;
	}

	protected void setContext(ApplicationContext context) {
		this.context = context;
	}

	public void close() {
		setContext(null);
	}
}
